<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Customer
 */
class Customer extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->model('customer_m');
	}

	/**
	 * header
	 */
	function _head() {
		$this->load->view('common/header');
	}

	/**
	 * footer
	 */
	function _foot() {
		$footer_data['add_script'][] = 'https://ajaxzip3.github.io/ajaxzip3.js';
		$this->load->view('common/footer',$footer_data);
	}

	/**
	 * index
	 */
	public function index() {
		// header
		$this->_head();

		//
		//$this->load->library('session');
        // input
        $this->load->view('customer/insert');

        // footer
        $this->_foot();
	}

	/**
	 * search_id
	 */
	public function search_id() {
		// result
		$result = "";
		// login_id
		$login_id = $this->input->get('login_id');

		//
		echo "test";

		//
		if (!empty($login_id)) {

			// get login_id
			$query = "SELECT * FROM customer WHERE login_id LIKE '%{$login_id}%'";
			$rs = mysql_query($query);

			// check login_id
			while ($row = mysql_fetch_array($rs)) {
				// used login id
			    $result = "used login id";
			}
		}

		$data = array(
			'login_id' => $login_id,
			'result' => $result
			);

		// search_id
        $this->load->view('customer/search_id', $data);

	}

	/**
	 * check
	 */
	public function check() {


		// set_session
		//$this->session->set_userdata('login_id', $this->input->post('login_id'));
/*
$this->session->set_userdata('login_id', $this->input->post('login_id'));


*/

		// get parameter
		$login_id = $this->input->post('login_id');
		$password = $this->input->post('password');
		$email = $this->input->post('email');
		$first_name = $this->input->post('first_name');
		$last_name = $this->input->post('last_name');
		$first_name_kana = $this->input->post('first_name_kana');
		$last_name_kana = $this->input->post('last_name_kana');



		$data = array(
			'login_id' => $login_id,
			'password' => $password,
			'email' => $email,
			'first_name' => $first_name,
			'last_name' => $last_name,
			'first_name_kana' => $first_name_kana,
			'last_name_kana' => $last_name_kana
			);


		// check





		// hearder
		$this->_head();

		// result
		if ( (strlen($login_id) < 1)
			or  (strlen($password) < 1)
			or  (strlen($email) < 1)
			or  (strlen($first_name) < 1)
			or  (strlen($last_name) < 1)
			or  (strlen($first_name_kana) < 1)
			or  (strlen($last_name_kana) < 1)) {
			echo "login id ";
	        $this->load->view('customer/insert', $data);

		} else {
			echo "ok";
			// confirm
	        $this->load->view('customer/confirm', $data);
		}

		// confirm
        //$this->load->view('customer/confirm', $data);

		// footer
		$this->_foot();
	}

	/**
	 * regist
	 */
	public function regist() {
		// set parameter
		$data = array(
			'login_id' => $this->input->post('login_id'),
			'password' => $this->input->post('password'),
			'email' => $this->input->post('email'),
			'first_name' => $this->input->post('first_name'),
			'last_name' => $this->input->post('last_name'),
			'first_name_kana' => $this->input->post('first_name_kana'),
			'last_name_kana' => $this->input->post('last_name_kana')
			);


/*
		$data = array(
			'login_id' => $this->session->userdata('login_id');,
			'password' => $this->session->userdata('password'),
			'email' => $this->session->userdata('email'),
			'first_name' => $this->session->userdata('first_name'),
			'last_name' => $this->session->userdata('last_name'),
			'first_name_kana' => $this->session->userdata('first_name_kana'),
			'last_name_kana' => $this->session->userdata('last_name_kana')
			);

*/

		//$data = $this->session->all_userdata();

		// insert
		$this->customer_m->regist($data);



		// hearder
		$this->_head();

		// test
        $this->load->view('customer/complete');

		// footer
		$this->_foot();
	}
	
	public function guest() {
		$date = array();
		$date['url'] = $this->input->get('url');
		
		$this->_head();
		$this->load->view('customer/guest_v',$date);
		$this->_foot();
	}

	public function guest_regist() {

		$guest_data["email"] = $this->input->post('email');
		$guest_data["first_name"] = $this->input->post('first_name');
		$guest_data["last_name"] = $this->input->post('last_name');
		$guest_data["first_name_kana"] = $this->input->post('first_name_kana');
		$guest_data["last_name_kana"] = $this->input->post('last_name_kana');
		$guest_data["zip21"] = $this->input->post('zip21');
		$guest_data["zip22"] = $this->input->post('zip22');
		$guest_data["pref21"] = $this->input->post('pref21');
		$guest_data["addr21"] = $this->input->post('addr21');
		$guest_data["strt21"] = $this->input->post('strt21');

		//TODO:validation

		$rtn_url = $this->input->post('url');
		$this->session->set_userdata(array('guest_data' => $guest_data,'guest_ok'=>TRUE));
		redirect(base_url()  ."index.php/cart/");
	}
	
}


/* End of file customer.php */
/* Location: s./zswebshop/controllers/customer.php */
